﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Common.Utilities.Dispatcher;
using Workflows.Components.TextMining.Properties;

namespace Workflows.Components.TextMining.NamedEntities
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class OrganizationEncodingComponent:WorkflowComponentBase
    {
        #region Overrides of WorkflowComponentBase

        private OrganizationEncodingInstruction _Instruction;
        /// <summary>an object that encapsulate instruction settings.</summary>
        public override InstructionBase Instruction
        {
            get { return _Instruction; }
            set { _Instruction = (OrganizationEncodingInstruction) value; }
        }

        private OrganizationEncodingOutput _Output;
        /// <summary>an object to encapsulate output</summary>
        public override ResultBase Output
        {
            get { return _Output; }
            set { _Output = (OrganizationEncodingOutput) value; }
        }

        #endregion

        /// <summary>
        /// 
        /// </summary>
        public OrganizationEncodingComponent():base()
        {
            this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
            this.ComponentCategory = WorkflowComponentCategory.TextMining.ToString();
            this.ComponentName = "Organization";
            this.Description = "Recognize organizations from table field and match them using pattern reverse index";
            this.ComponentIcon = Resources.home;
            this.ComponentImage = Resources.Home1;

            this._Instruction=new OrganizationEncodingInstruction(
                this.ComponentID,Guid.Empty,string.Empty,string.Empty,
                string.Empty, string.Empty, string.Empty, string.Empty,
                new Dictionary<string, List<string>>(), 
                new Dictionary<string, double>(),
                new Dictionary<string, double>(), 
                0.55, string.Empty);
            this._Output=new OrganizationEncodingOutput(
                this.ComponentID,Guid.Empty,string.Empty,0,0);
        }

        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
            this.Instruction.Serialize(ref xDoc, ref xNode);
            return xNode;
        }

        public override WorkflowComponentBase Instantiate(XmlNode xNode)
        {
            OrganizationEncodingComponent component = (OrganizationEncodingComponent)base.Instantiate(xNode);
            component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
            return component;
        }
    }
}
